package com.itheima.controller;

import com.itheima.alioss.spring.boot.autoconfigure.common.AliOSSUtils;
import com.itheima.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * The type File controller.
 */
@Slf4j
@RestController
public class FileController {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    /**
     * Upload result.
     *
     * @param image the image
     * @return the result
     */
    @PostMapping("upload")
    public Result<?> upload(MultipartFile image){
        try {
            String upload = aliOSSUtils.upload(image);
            return Result.success(upload);
        } catch (IOException e) {
            log.error("文件上传失败",e);
        }
        return Result.error("上传失败");
    }
}
